﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace FaWorks.WebSite.Models
{
    public class SitemapItem
    {
        public Guid ID{ get; set; }
        public string Name{ get; set; }
        public string Location { get; set; }
        public string Icon { get; set; }
        public int Index { get; set; }

        public List<SitemapItem> Childs { get; private set; }

        public void AddChild(SitemapItem sitemapItem)
        {
            if (this.Childs == null) {
                this.Childs = new List<SitemapItem>();
            }
            this.Childs.Add(sitemapItem);
        }

        public void RemoveChild(SitemapItem sitemapItem)
        {
            this.Childs.Remove(sitemapItem);
        }
    }

    public class SitemapItemCompare<T>
        : IComparer<T>
        where T : SitemapItem
    {

        public int Compare(T x, T y)
        {
            return Int32.Parse(x.Index.ToString().PadRight(9, '0')) - Int32.Parse(y.Index.ToString().PadRight(9, '0'));
        }
    }
}